Repository navigation
Conversation
@EnableReactiveMethodSecurity now has securedEnabled and jsr250Enabled attributes, as @EnableMethodSecurity does. They add before-method interceptors backed by the new SecuredReactiveAuthorizationManager and Jsr250ReactiveAuthorizationManager, which resolve the annotations the same way as their servlet counterparts and use GrantedAuthorityDefaults and RoleHierarchy beans when present. Closes spring-projectsgh-5103 Signed-off-by: Rohit Behera <126186063+r0h1tb@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes gh-5103
Reactive method security only supported
@PreAuthorize,@PostAuthorize,@PreFilterand@PostFilter.@RolesAllowed,@PermitAll,@DenyAlland@Securedwere ignored onMono/Fluxmethods, and adding@EnableMethodSecurity(jsr250Enabled = true)to a WebFlux app does not help (see the discussion in the issue).This adds
securedEnabledandjsr250Enabledto@EnableReactiveMethodSecurity, mirroring@EnableMethodSecurity:core:Jsr250ReactiveAuthorizationManagerandSecuredReactiveAuthorizationManager. They delegate toJsr250AuthorizationManagerandSecuredAuthorizationManager, so annotation lookup (class level, interfaces, meta-annotations, the duplicate-annotation check) and the role prefix behave exactly as in the servlet stack.@PermitAllis granted even when noAuthenticationis present, as it is there.AuthorizationManagerBeforeReactiveMethodInterceptorgetssecured()andjsr250()factories with the existingSECUREDandJSR250orders.config:ReactiveSecuredMethodSecurityConfigurationandReactiveJsr250MethodSecurityConfiguration, imported byReactiveMethodSecuritySelectorwhen the attributes are set. They pick upGrantedAuthorityDefaults(JSR-250) andRoleHierarchybeans and go through the existingObjectPostProcessor, so authorization observations work as for@PreAuthorize. The interceptor beans use thesecuredAuthorizationMethodInterceptorandjsr250AuthorizationMethodInterceptornames thatMethodSecurityAdvisorRegistraralready registers as advisors.useAuthorizationManager = falsethe attributes fail fast with anIllegalStateException, since the legacy configuration cannot honor them.Tests: unit tests for both managers and the new interceptor factories,
ReactiveSecuredAndJsr250MethodSecurityConfigurationTestscoveringMonoandFluxmethods, class-level and interface annotations (JDK proxy),@PreAuthorizeand@RolesAllowedon the same method, both attributes together, the attributes being off by default,GrantedAuthorityDefaults,RoleHierarchy, observations and theuseAuthorizationManager = falsefailure, andKotlinReactiveSecuredAndJsr250MethodSecurityTestsforsuspendfunctions andFlow../gradlew formatand:spring-security-core:check :spring-security-config:checkpass locally on JDK 25.A few choices you may want to weigh in on:
PreAuthorizeReactiveAuthorizationManager, so they can be used with the new interceptor factories directly. They could be package-private instead if you prefer to keep the API smaller.@PreAuthorizebeans already do. So, as today,@EnableMethodSecurityand@EnableReactiveMethodSecuritywith the same annotation type enabled cannot share one context.@RolesAllowedand@Secureduse aRoleHierarchybean, as in the servlet stack. Reactive@PreAuthorizeexpressions do not use one yet, so the two can disagree in the same app. That looks worth a separate issue.@since 7.3sincemainis at 7.2.1-SNAPSHOT, and the 7.3whats-newpage does not exist yet. Happy to adjust the version or add the entry.